##snippets/urls.py
from django.contrib import admin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework.urlpatterns import format_suffix_patterns

from snippets import views
from rest_framework.schemas import get_schema_view

# Create a router and register our ViewSets with it.
from snippets.views import UserViewSet, TBookViewSet

router = DefaultRouter()
router.register(r'snippets', views.SnippetViewSet, basename='snippet')
router.register(r'users', views.UserViewSet, basename='user')
router.register(r'books', views.TBookViewSet, basename='tbook')
router.register(r'bookmanager', views.TBookManagerViewSet, basename='tbookmanager')

tbook_list = TBookViewSet.as_view({'get': 'list'})
tbook_detail = TBookViewSet.as_view({'post': 'retrieve'})

schema_view = get_schema_view(title='Pastebin API')

# API URL现在由路由器自动确定
urlpatterns = [
    path('admin/', admin.site.urls),
    path('schema/', schema_view),
    # path('books/', tbook_list, name='tbook-list'),
    # path('books/<int:pk>/', tbook_list, name='tbook-detail'),
    path('', include(router.urls)),
]

# 可浏览API的登录和注销视图
urlpatterns += [
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

##这边不在需要格式化 url
# urlpatterns = format_suffix_patterns(urlpatterns)
